home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / cit_src_7H21.lha / reset_net.c < prev    next >
C/C++ Source or Header  |  1997-07-27  |  4KB  |  151 lines

  1.  /*
  2.  *                              Clean.c
  3.  *
  4.  * Cleanses a room of a user.
  5.  */
  6.  
  7. #include "ctdl.h"    /* header file  */
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <math.h>
  12. #include <ctype.h>
  13. #include <time.h>
  14. #include <proto/exec.h>
  15. #include <dos/dos.h>
  16. #include <pragmas/dos_pragmas.h>
  17. #include "exec/memory.h"
  18. #include "exec/ports.h"
  19. #include "exec/exec.h"
  20.  
  21.  
  22. /*
  23.  *                              Contents
  24.  *
  25.  *      crashout()              irrecoverable error
  26.  *      doRest()                Read msgs.
  27.  *      handle()                Inserts msg into room slot, etc.
  28.  *      indexRooms()            build RAM index to ctdlroom.sys
  29.  *      init()                  Open up files for recovery effort.
  30.  *      main()                  Master control.
  31.  *      noteRoom()              enter room into RAM index
  32.  */
  33.  
  34. extern CONFIG  cfg;             /* The main variable to be saved */
  35. extern MessageBuffer msgBuf;    /* The -sole- message buffer */
  36. extern FILE    *msgfl, *msgfl2; /* file descriptor for the msg file */
  37. extern rTable  *roomTab;        /* RAM index of rooms */
  38. extern aRoom   roomBuf;         /* room buffer */
  39. extern FILE    *roomfl;         /* file descriptor for rooms    */
  40. extern int     thisRoom;        /* room currently in roomBuf    */
  41. extern NetTable  *netTab;       /* RAM index of nodes           */
  42. extern FILE    *netfl;          /* file ctdlnet.sys */
  43. extern NetBuffer   netBuf;      /* buffer for ctdlnet.sys */
  44.  
  45.  
  46. char init(void);
  47. int  mPrintf(char *format, ...) {return 0; }  /* stub to quiet the linker */
  48.  
  49. short fflag = FALSE;   /* TRUE = update net info */
  50.  
  51. /*
  52.  * crashout()
  53.  *
  54.  * Irrecoverable error?  Crash out of the program.
  55.  */
  56. void crashout(str)
  57. char *str;
  58. {
  59.     exit(printf(str));
  60. }
  61.  
  62. /*
  63.  * init()
  64.  *
  65.  * This will set up the files for recovery.
  66.  */
  67. char init()
  68. {
  69.     SYS_FILE temp;
  70.  
  71.     cfg.weAre = UTILITY;
  72.     if (!readSysTab(TRUE, TRUE)) crashout("\nDisaster!  I need CTDLTABL.SYS!");
  73.  
  74.     if (access(LOCKFILE, 0) != -1) {
  75.         printf("Please do not run Clean from Outside Commands.\n");
  76.         return FALSE;
  77.     }
  78.  
  79.     cfg.weAre = UTILITY;
  80.     mvToHomeDisk(&cfg.homeArea);
  81.     /* open message file */
  82.  
  83.     InitMsgBase();
  84.     makeSysName(temp, "ctdlroom.sys", &cfg.roomArea);
  85.  
  86.     /* open room file */
  87.     openFile(temp, &roomfl);
  88.     initRoomBuf(&roomBuf);
  89.  
  90.     /* open the net data file */
  91.     makeSysName(temp, "ctdlnet.sys", &cfg.netArea);
  92.     openFile(temp, &netfl);
  93.     initNetBuf(&netBuf);
  94.  
  95.     return TRUE;
  96. }
  97.  
  98. /*
  99.  * main()
  100.  *
  101.  * This directs salvage proceedings and collects profits.
  102.  */
  103. int main(int, char **);
  104. int main(argc, argv)
  105. int argc;
  106. char **argv;
  107. {
  108.   int node, slot;
  109.     if( argc > 1 )
  110.       {
  111.       if( strcmp(argv[1], "reset") == 0)fflag = TRUE;
  112.       };
  113.     printf("Citadel Reset Room Netted Information %s\n%s\n", VERSION_NAME, COPYRIGHT);
  114.     if ( init() )
  115.       {
  116.       for(node = 0; node < cfg.netSize; node++)
  117.         {
  118.         if( !netTab[node].ntflags.in_use )continue;
  119.         printf("\nProcessing :%c%c%c[%d]",
  120.         (isprint(netTab[node].ntShort[0]) ? netTab[node].ntShort[0] : '*'),
  121.         (isprint(netTab[node].ntShort[1]) ? netTab[node].ntShort[1] : '*'),
  122.         (isprint(netTab[node].ntShort[2]) ? netTab[node].ntShort[2] : '*'),node);
  123.  
  124.         getNet(node,&netBuf);
  125.  
  126.         for( slot=0; slot < SHARED_ROOMS; slot++)
  127.           {
  128.           if( !roomTab[netTabRoomSlot(node, slot)].rtflags.SHARED)continue;
  129.           printf("\n...Room:%s(%d) last:%ld NetTab.lastMess:%ld netBuf.lastMess:%ld",
  130.           roomTab[netTabRoomSlot(node, slot)].rtname, slot,
  131.           roomTab[netTabRoomSlot(node, slot)].rtlastMessage,
  132.           netTab[node].netTRooms[slot].lastMess,
  133.           netBuf.netRooms[slot].lastMess);
  134.  
  135.           if( fflag )
  136.             {
  137.             netTab[node].netTRooms[slot].lastMess = 0;
  138.             netBuf.netRooms[slot].lastMess = 0;
  139.             };
  140.           };
  141.  
  142.         if( fflag )putNet(node,&netBuf);
  143.         };
  144.  
  145.       };
  146.     if( fflag ) writeSysTab();
  147.     printf("\n...finished\n");
  148.     return 0;
  149. }
  150.  
  151.